
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">

    <title>{$sysPageTitle}</title>

    <link href="__PUBLIC__/images/favicon.ico" rel="shortcut icon" />

    <!-- Bootstrap core CSS -->
    <link rel="stylesheet" href="__PUBLIC__/css/bootstrap.min.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-theme.min.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/dashboard.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/icheck/all.css" />
    <link rel="stylesheet" href="__PUBLIC__/js/bootstrapvalidator/css/bootstrapValidator.min.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-datetimepicker.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/select2/select2.min.css" />
</head>

<body>

<include file="Common/topNav" />

<div class="container-fluid">
    <div class="row">
        <include file="Common/leftMenu" />
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="cont-title clearfix">
                <div class="title">行程列表</div>
            </div>
            <include file="trip_search" />
            <div class="table-responsive" style="overflow: visible;">
                <table class="table table-striped table-hover" id="tableData">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>客票号</th>
                        <th>起止地</th>
                        <th>旅客名称</th>
                        <th>最低赏金</th>
                        <th>联系方式</th>
                        <th>行程描述</th>
                        <th>审核状态</th>
                        <th>行程状态</th>
                        <th>发布者</th>
                        <th>发布时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="trip_list">
                    <empty name="listData">
                        <tr>
                            <td colspan="12">没有相关记录</td>
                        </tr>
                    </empty>
                    <foreach name="listData" item="data">
                        <tr>
                            <td>{$key|getLineNum=$nowPage,$pageSize}</td>
                            <td>{$data.ticket_id}</td>
                            <td>{$data.origin} - {$data.destination}</td>
                            <td>{$data.real_name}</td>
                            <td>{$data.reward_min|number_format=2}</td>
                            <td>
                                <if condition="$data['contact']['tel']"> <p style="margin-bottom: 0px;">手机：{$data.contact.tel}</p></if>
                                <if condition="$data['contact']['wx']"> <p style="margin-bottom: 0px;">微信：{$data.contact.wx}</p></if>
                            </td>
                            <td class="destination_content" title="{$data.real_name} - {$data.ticket_id}" data-toggle="popover" data-content="{$data.description|default='暂无行程描述'}">{$data.description|msubstr=###,0,10,"utf-8",true}</td>
                            <td class="status_content" <if condition="$data['status'] eq 2">title="{$data.real_name} - {$data.ticket_id}" data-toggle="popover" data-content="{$data.remark|default='其它'}"</if>>
                                <div class="btn-group" style="margin-top:-5px;margin-bottom:-5px;">
                                    <button type="button" onclick="chooseThis(this)" class="btn btn-link dropdown-toggle" data-toggle="dropdown" style="margin-top: -2px;text-decoration:none; ">
                                        <switch name="data.status">
                                            <case value="0"><span class="label label-info">审核中</span></case>
                                            <case value="1"><span class="label label-success">审核通过</span></case>
                                            <case value="2"><span class="label label-warning">审核未通过</span></case>
                                            <case value="3"><span class="label label-default">已结束</span></case>
                                            <case value="4"><span class="label label-danger">已删除</span></case>
                                            <default /><span class="label label-default">未知</span>
                                        </switch>
                                    </button>
                                    <ul class="dropdown-menu" style="font-size: 14px;">
                                        <li><a href="javascript:void(0);" id="{$data.id}" statusId="0" onclick="setStatus(this)">审核中</a></li>
                                        <li><a href="javascript:void(0);" id="{$data.id}" statusId="1" onclick="setStatus(this)">审核通过</a></li>
                                        <li><a href="javascript:void(0);" id="{$data.id}" statusId="2" onclick="setStatus(this)">审核未通过</a></li>
                                        <li><a href="javascript:void(0);" id="{$data.id}" statusId="3" onclick="setStatus(this)">已结束</a></li>
                                        <li><a href="javascript:void(0);" id="{$data.id}" statusId="4" onclick="setStatus(this)">已删除</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td>
                                <switch name="data.state">
                                    <case value="0"><span class="label label-info">审核中</span></case>
                                    <case value="1"><span class="label label-primary">接单中</span></case>
                                    <case value="2"><span class="label label-success">订单已满</span></case>
                                    <case value="3"><span class="label label-default">接单结束</span></case>
                                    <case value="4"><span class="label label-info">已暂停接单</span></case>
                                    <case value="5"><span class="label label-warning">已关闭</span></case>
                                    <case value="6"><span class="label label-danger">已删除</span></case>
                                    <default /><span class="label label-default">其它</span>
                                </switch>
                            </td>
                            <td>{$data.user.real_name}</td>
                            <td>{$data.add_time|date="Y-m-d H:i",###}</td>
                            <td>
                                <if condition="$data['status'] eq '0' || $data['state'] eq '0'">
                                    <a thisId="{$data['id']}" class="edit-air" href="javascript:void(0);">设置航班</a>
                                <else/>
                                    <a thisId="{$data['id']}" class="query-air" href="javascript:void(0);" style="color:#666;">航班详情</a>
                                </if>
                            </td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
                <div class="page">
                    {$page}
                </div>
            </div>
        </div>
    </div>
</div>


<include file="Common/modalHtmls" />
<script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/icheck.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/bootstrapvalidator/js/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap-datetimepicker.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/select2/select2.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/select2/i18n/zh-CN.js"></script>
<script type="text/javascript">
    $(function () {
        $(".destination_content").popover({
            trigger: "hover",
            container: "body",
            placement: "right"
        });
        $(".status_content").popover({
            trigger: "hover",
            container: "body",
            placement: "right"
        });
        $("#tableData").on("click",".edit-air",function () {
            var id = $(this).attr("thisId");
            common.getHtml("{:U('Admin/Airway/setAir')}", {tripId:id}, function (html) {
                common.closeLoading();
                $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
            });
        });
        $("#tableData").on("click",".query-air",function () {
            var id = $(this).attr("thisId");
            common.getHtml("{:U('Admin/Airway/queryAir')}", {tripId:id}, function (html) {
                common.closeLoading();
                $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
            });
        });
        var options = {
            url: "{:U('Admin/User/showUserList')}",
            pageSize: 30,
            value: "id",
            name: "name"
        };
        showUserList(options);
        $("#trip_from_date,#trip_to_date").datetimepicker({
            format: "yyyy-mm-dd",
            language: "ch",
            pickDate: true,
            pickTime: false,
            autoclose: true,
            minView: 2
        });
    });

    function chooseThis(obj) {
        $("#trip_list").find("tr").css({"background-color":""});
        $(obj).parents("tr").css({"background-color":"#D2ECF9"});
    }

    function setStatus(obj) {
        var statusId = $(obj).attr("statusId");
        var id = $(obj).attr("id");
        var statusName = $(obj).html();
        var msg = '确定将行程状态修改为【<span style="color:#FF0000;">'+statusName+'</span>】吗？';
        var span = '';
        switch(statusId) {
            case '0':
                span = '<span class="label label-info">审核中</span>';
                break;
            case '1':
                span = '<span class="label label-success">审核通过</span>';
                break;
            case '2':
                span = '<span class="label label-warning">审核未通过</span>';
                var remark = '请选择未通过原因：<div class="form-group" style="margin-top: 15px;"><select id="refuse_remark" class="form-control">';
                remark += '<option value="客票号和旅客姓名不对应">1.客票号和旅客姓名不对应</option>';
                remark += '<option value="暂不支持国内航班">2.暂不支持国内航班</option>';
                remark += '<option value="行程已过期">3.行程已过期</option>';
                remark += '</select></div>';
                msg += remark;
                break;
            case '3':
                span = '<span class="label label-default">已结束</span>';
                break;
            case '4':
                span = '<span class="label label-danger">已删除</span>';
                break;
            default:
                span = '<span class="label label-default">未知</span>';
                break;
        }
        common.confirm("提示", msg, function () {
            var param = {id: id,statusId:statusId};
            if ($("#refuse_remark").length) {
                param.remark = $("#refuse_remark").val();
            }
            common.ajax("{:U('Admin/Airway/setTripStatus')}", param, function (rs) {
                if (rs.status) {
                    $(obj).parent().parent().prev("button").html(span);
                } else {
                    common.alert("提示",rs.msg);
                }
            });
        });
    }

    function showUserList(options) {
        var select2Option = {
            language: "zh-CN",
            allowClear: true,
            placeholder: options["placeholder"] || "全部",
            ajax:{
                url: options["url"],
                type: "post",
                dataType: "json",
                delay: 250,
                data: function(params){
                    // 传递到后端的参数
                    return {
                        // 搜索框内输入的内容
                        selectInput: params.term,
                        // 当前页
                        curPage: params.page || 1,
                        // 每页显示多少条记录，默认10条
                        pageSize: options["pageSize"] || 30
                    };
                },
                cache:true,
                processResults: function (res, params) {
                    params.page = params.page || 1;
                    var cbData = [];
                    var data = res.data;
                    var len = data.length;
                    for(var i= 0; i<len; i++){
                        var option = {"id": data[i]["id"], "text": data[i]["real_name"]};
                        cbData.push(option);
                    }
                    return {
                        results: cbData,
                        pagination: {
                            more: params.page < res.total
                        }
                    };
                }
            },
            escapeMarkup: function (markup) {
                // 字符转义处理
                return markup;
            },
            // 最少输入N个字符才开始检索，如果想在点击下拉框时加载数据，请设置为 0
            minimumInputLength: 0
        };
        $("#user_id").select2(select2Option);
        var selectedUserId = "{$user_id}";
        if (selectedUserId) {
            var option = new Option("{$searchUserName}", selectedUserId, true, true);
            $("#user_id").append(option);
        }
    }
</script>
</body>
</html>
